﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine;
using Microsoft.Xna.Framework;

namespace EngineDrawer.Effects.ParticleSystem
{
    public class ExplosionSystem : DrawableGameComponent
    {
        private ExplosionParticleSystem _explosionParticleSystem;
        private ExplosionSmokeParticleSystem _explosionSmokeParticleSystem;

        public ExplosionSystem(Game game) : base(game)
        {
        }
        public override void Initialize()
        {
            _explosionParticleSystem = new ExplosionParticleSystem(Game, Game.Content);
            _explosionSmokeParticleSystem = new ExplosionSmokeParticleSystem(Game, Game.Content);
            Game.Components.Add(_explosionParticleSystem);
            Game.Components.Add(_explosionSmokeParticleSystem);


            base.Initialize();
        }
        public void Explode(Vector3 position,Vector3 direction)
        {
            const int explosionParticlesNumber = 30;
            const int explosionSmokeParticlesNumber = 50;

            for (int i = 0; i < explosionParticlesNumber; i++)
                _explosionParticleSystem.AddParticle(position, direction);

            for (int i = 0; i < explosionSmokeParticlesNumber; i++)
                _explosionSmokeParticleSystem.AddParticle(position, direction);

        }
        public override void Update(GameTime gameTime)
        {
            _explosionParticleSystem.SetCamera(World.ViewMatrix, World.ProjMatrix);
            _explosionSmokeParticleSystem.SetCamera(World.ViewMatrix, World.ProjMatrix);

            base.Update(gameTime);
        }
        public World World
        {
            get { return (World) Game.Services.GetService(typeof (World)); }
        }
    }
}
